package Operation;


import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2023-12-31
 * Time: 22:10
 */
public class DelOperation implements Operation{
    @Override
    public void work(BookList book) {
        System.out.println("请输入要删除的书名");
        Scanner scanner=new Scanner(System.in);
        String name=scanner.nextLine();
        int  size=book.getUsedSize();
        int i=0;
        int pos=0;
        for (; i < size; i++) {
            if(book.getBook(i).getName().equals(name)){
                 pos=i;
                 break;
            }
        }
        if(i==size){
            System.out.println("要删除的书不存在");
        }else{
            for (int j = pos; j <size-1 ; j++) {
                book.setBook(j,book.getBook(j+1));
            }
            book.setUsedSize(size-1);
            System.out.println("删除成功");
        }
    }
}
